package com.skku.selab.erp.db.sql;

import java.util.*;
import java.sql.*;

public class TupleTable{
	
	/**
	 * @param initCon
	 * @param initTableName
	 */
	public TupleTable() {
	}

	/**
	 * @return
	 */
	static public Vector<Tuple> getEntireTable(Connection con, String tableName)	{
		Vector<Tuple> tupleVector = new Vector<Tuple>();
		Tuple tempTuple = new Tuple();
		ResultSet rs = null;

		rs = DML.selectFrom(con, "*", tableName);

		try{
			//get tuples and build a table
			while(rs.next()){
				tempTuple.idx = rs.getString(1);
				tempTuple.member_id = rs.getString(2);
				tempTuple.password = rs.getString(3);
				tempTuple.name = rs.getString(4);
				tempTuple.social_number = rs.getString(5);
				tempTuple.post_number = rs.getString(6);
				tempTuple.address_1 = rs.getString(7);
				tempTuple.address_2 = rs.getString(8);
				tempTuple.contact = rs.getString(9);
				tempTuple.email = rs.getString(10);
				tempTuple.shop_name = rs.getString(11);
				tempTuple.shop_business_number = rs.getString(12);
				tempTuple.shop_post_number = rs.getString(13);
				tempTuple.shop_address_1 = rs.getString(14);
				tempTuple.shop_address_2 = rs.getString(15);
				tempTuple.shop_phone_number = rs.getString(16);
				tempTuple.shop_representative = rs.getString(17);
				tempTuple.shop_representative_phone = rs.getString(18);
				tempTuple.shop_email = rs.getString(19);
				tempTuple.shop_homepage = rs.getString(20);
				tempTuple.shop_kind = rs.getString(21);
				tempTuple.shop_history = rs.getString(22);
				tempTuple.shop_size = rs.getString(23);
				tempTuple.target_year = rs.getString(24);
				tempTuple.target_taste = rs.getString(25);
				tempTuple.target_cost_0 = rs.getString(26);
				tempTuple.target_cost_1 = rs.getString(27);
				tempTuple.target_cost_2 = rs.getString(28);
				tempTuple.target_cost_3 = rs.getString(29);
				tempTuple.target_cost_4 = rs.getString(30);
				tempTuple.target_sourcing_0 = rs.getString(31);
				tempTuple.target_sourcing_1 = rs.getString(32);
				tempTuple.sign_in_date = rs.getString(33);
				tempTuple.modified_date = rs.getString(34);

				tupleVector.add(tempTuple);
			}
			rs.close();
		}	catch(SQLException se) {
			System.out.println(se.toString());
		}	finally	{
		}
		return tupleVector;
	}
	

	/**
	 * @param condition
	 * @return
	 */
	/*
	public Vector<Tuple> selectTuple(Connection con, String tableName, String col, String where){
		Vector<Tuple> tupleVector = new Vector<Tuple>();
		Tuple tempTuple = new Tuple();
		ResultSet rs = null;

		//rs = DML.selectFrom(con, "*", tableName);
		rs = DML.selectFrom(con, col, tableName, where);

		try{
			//get tuples and build a table
			while(rs.next()){
				tempTuple.idx = rs.getString(1);
				tempTuple.member_id = rs.getString(2);
				tempTuple.password = rs.getString(3);
				tempTuple.name = rs.getString(4);
				tempTuple.social_number = rs.getString(5);
				tempTuple.post_number = rs.getString(6);
				tempTuple.address_1 = rs.getString(7);
				tempTuple.address_2 = rs.getString(8);
				tempTuple.contact = rs.getString(9);
				tempTuple.email = rs.getString(10);
				tempTuple.shop_name = rs.getString(11);
				tempTuple.shop_business_number = rs.getString(12);
				tempTuple.shop_post_number = rs.getString(13);
				tempTuple.shop_address_1 = rs.getString(14);
				tempTuple.shop_address_2 = rs.getString(15);
				tempTuple.shop_phone_number = rs.getString(16);
				tempTuple.shop_representative = rs.getString(17);
				tempTuple.shop_representative_phone = rs.getString(18);
				tempTuple.shop_email = rs.getString(19);
				tempTuple.shop_homepage = rs.getString(20);
				tempTuple.shop_kind = rs.getString(21);
				tempTuple.shop_history = rs.getString(22);
				tempTuple.shop_size = rs.getString(23);
				tempTuple.target_year = rs.getString(24);
				tempTuple.target_taste = rs.getString(25);
				tempTuple.target_cost_0 = rs.getString(26);
				tempTuple.target_cost_1 = rs.getString(27);
				tempTuple.target_cost_2 = rs.getString(28);
				tempTuple.target_cost_3 = rs.getString(29);
				tempTuple.target_cost_4 = rs.getString(30);
				tempTuple.target_sourcing_0 = rs.getString(31);
				tempTuple.target_sourcing_1 = rs.getString(32);
				tempTuple.sign_in_date = rs.getString(33);
				tempTuple.modified_date = rs.getString(34);

				tupleVector.add(tempTuple);
			}
			rs.close();
		}	catch(SQLException se) {
			System.out.println(se.toString());
		}	finally	{
		}
		return tupleVector;
	}
	*/
	
	/**
	 * @param inputTuple
	 * @return
	 */
	static public int insertTuple(Connection con, String tableName, Tuple inputTuple){
		int irs=-1;
		String fields = new String("idx,member_id,password,name," +
				"social_number,post_number," +
				"address_1,address_2," +
				"contact,email,shop_name," +
				"shop_business_number,shop_post_number," +
				"shop_address_1,shop_address_2,shop_phone_number," +
				"shop_representative,shop_representative_phone," +
				"shop_email,shop_homepage,shop_kind," +
				"shop_history,shop_size,target_year," +
				"target_taste,target_cost_0,target_cost_1," +
				"target_cost_2,target_cost_3,target_cost_4," +
				"target_sourcing_0,target_sourcing_1" +	"," +
				"sign_in_date,modified_date");
		
		String tuple = new String(inputTuple.idx + "," + inputTuple.member_id + "," + inputTuple.password + "," + inputTuple.name + "," + 
				inputTuple.social_number + "," + inputTuple.post_number + "," + 
				inputTuple.address_1 + "," + inputTuple.address_2 + "," + 
				inputTuple.contact + "," + inputTuple.email + "," + inputTuple.shop_name + "," + 
				inputTuple.shop_business_number + "," + inputTuple.shop_post_number + "," + 
				inputTuple.shop_address_1 + "," + inputTuple.shop_address_2 + "," + inputTuple.shop_phone_number + "," + 
				inputTuple.shop_representative + "," + inputTuple.shop_representative_phone + "," + 
				inputTuple.shop_email + "," + inputTuple.shop_homepage + "," + inputTuple.shop_kind + "," + 
				inputTuple.shop_history + "," + inputTuple.shop_size + "," + inputTuple.target_year + "," + 
				inputTuple.target_taste + "," + inputTuple.target_cost_0 + "," + inputTuple.target_cost_1 + "," + 
				inputTuple.target_cost_2 + "," + inputTuple.target_cost_3 + "," + inputTuple.target_cost_4 + "," + 
				inputTuple.target_sourcing_0 + "," + inputTuple.target_sourcing_1 + "," +  
				"'" + inputTuple.sign_in_date + "','" + inputTuple.modified_date + "'");
		
		irs = DML.insertInto(con, tableName, " (" + fields + ") ", " (" + tuple + ") ");
		return irs;
	}
}
